import axios from 'axios';
import { Message } from 'element-ui';
// import base from '../api/api'
const service = axios;
service.defaults.withCredentials=true;
service.defaults.headers['X-Requested-With']='XMLHttpRequest';


service.interceptors.request.use(
    config => {
        return config;
    }, error => {
        return Promise.reject(error);
    });

service.interceptors.response.use(
    response => {
        // if(typeof response.data == 'string' && response.data.includes('<title>redirect</title>')) {
        //     const href = window.location.href;
        //     window.location.href = `${base.URL}/api/redirect?redirect_url=` + href;
        // }
        return response;
    },
    error => {
        if (error.response) {
            switch (error.response.status) {
                case 500:
                    // Message.error('服务器错误');
                    break;
                case 401:
                    // 权限错误
                    // const href = window.location.href;
                    // window.location.href = `${base.URL}/api/redirect?redirect_url=` + href;
                    break;
            }
            return Promise.reject(error.response.data);
        } else {
            return Promise.reject(error.message);
        }
    });

export default service;
